package com.xxwy.ddu.security.app.social.signup;

import com.xxwy.ddu.security.code.authentication.qq.connection.MySpringSocialConfigurer;
import com.xxwy.ddu.security.code.properties.SecurityConstants;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * @author xxwy
 * on 2018/8/30 0030
 * 在spring初始化容器之前和之后都要经过这两个方法
 */
@Component
public class SpringSocialConfigurerPostProcessor implements BeanPostProcessor {


    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }

    /**
     *
     * @param bean
     * @param beanName
     * @return
     * @throws BeansException
     */
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if(StringUtils.equals(beanName,"xxSocialConfigurer")){
            MySpringSocialConfigurer mySpringSocialConfigurer = (MySpringSocialConfigurer) bean;
            mySpringSocialConfigurer.signupUrl(SecurityConstants.DEFAULT_SOCIAL_USER_INFO_URL);
        }
        return null;
    }
}
